package org.digitarts.rtms.spring.collectors.shell.commands;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CellParser
{
	protected int		id		= 0;
	protected String	regex	= null;
	protected int		group	= 0;
	protected Pattern	parser	= null;

	public CellParser(int id, String regex, int group)
	{
		this.id = id;
		this.regex = regex;
		this.group = group;
		this.parser = Pattern.compile(regex);
	}

	public String parseCell(String cellValue)
	{
		Matcher m = parser.matcher(cellValue);
		if (m.matches())
		{
			m.group();
			return m.group(group);
		}
		else
		{
			return null;
		}
	}

	public int getId()
	{
		return id;
	}

	public int getGroup()
	{
		return group;
	}

}
